package utils;

import java.util.ArrayList;

//import count.counter.UserQueryClick.SortDate;

public class Sort {
	public static int[] quickSortInt(int[] pData, int left, int right) {
		int i = left, j = right;
		int middle, strTemp;

		middle = pData[(left + right) / 2];
		do {
			while ((pData[i] < middle) && (i < right))
				i++;
			while ((pData[j] > middle) && (j > left))
				j--;
			if (i <= j) {
				strTemp = pData[i];
				pData[i] = pData[j];
				pData[j] = strTemp;
				i++;
				j--;
			}
		} while (i <= j);
		// for (int t = 0; t < pData.length; t++)
		// System.out.print(pData[t] + " ");
		// System.out.println("");
		if (left < j) {
			quickSortInt(pData, left, j);
		}

		if (right > i)
			quickSortInt(pData, i, right);
		return pData;
	}

	public static ArrayList<SortPvClick> quickSortCredit(
			ArrayList<SortPvClick> list, int left, int right) {
		int i = left, j = right;
		int middle;
		SortPvClick strTemp = new SortPvClick();

		middle = list.get((left + right) / 2).credit;
		do {
			while ((list.get(i).credit > middle) && (i < right))
				i++;
			while ((list.get(j).credit < middle) && (j > left))
				j--;
			if (i <= j) {
				strTemp = list.get(i);
				list.set(i, list.get(j));
				list.set(j, strTemp);
				i++;
				j--;
			}
		} while (i <= j);
		if (left < j) {
			quickSortCredit(list, left, j);
		}

		if (right > i)
			quickSortCredit(list, i, right);
		return list;
	}

	public static ArrayList<SortPvClick> quickSortPrice(
			ArrayList<SortPvClick> list, int left, int right) {
		int i = left, j = right;
		double middle;
		SortPvClick strTemp = new SortPvClick();

		middle = list.get((left + right) / 2).price;
		do {
			while ((list.get(i).price > middle) && (i < right))
				i++;
			while ((list.get(j).price < middle) && (j > left))
				j--;
			if (i <= j) {
				strTemp = list.get(i);
				list.set(i, list.get(j));
				list.set(j, strTemp);
				i++;
				j--;
			}
		} while (i <= j);
		if (left < j) {
			quickSortPrice(list, left, j);
		}

		if (right > i)
			quickSortPrice(list, i, right);
		return list;
	}
/*
	public static ArrayList<SortDate> quickSortDate(ArrayList<SortDate> list,
			int left, int right) {
		int i = left, j = right;
		Date middle;
		SortDate strTemp = new SortDate();

		middle = list.get((left + right) / 2).date;
		do {
			while ((list.get(i).date.before(middle)) && (i < right))
				i++;
			while ((list.get(j).date.after(middle)) && (j > left))
				j--;
			if (i <= j) {
				strTemp = list.get(i);
				list.set(i, list.get(j));
				list.set(j, strTemp);
				i++;
				j--;
			}
		} while (i <= j);
		if (left < j) {
			quickSortDate(list, left, j);
		}

		if (right > i)
			quickSortDate(list, i, right);
		return list;
	}
*/
	public static void main(String[] argv) {
		int[] pData = { 1, 84, 85, 67, 600, 88, 999 };
		quickSortInt(pData, 0, pData.length - 1);
	}

	public static class SortPvClick {
		public String line;
		public int credit;
		public double price;

		public SortPvClick() {
			line = "";
			credit = 0;
			price = 0;
		}

		public SortPvClick(String line, int credit, double price) {
			this.line = line;
			this.credit = credit;
			this.price = price;
		}
	}
}
